class Order_settlement {
    /**
     * 折扣
     * @return {Promise<unknown>}
     * @constructor
     */
    OrderDiscount(total,discount){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/order/discount",
                method: "GET",
                data: {
                    total: total,
                    discount:discount
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增或修改地址
     * @param addressJson 地址Json
     * @return {Promise<boolean>} 布尔值
     */
    saveOrUpdateAddress(addressJson){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/order/settlement",
                method: "POST",
                data: {
                    addressJson: addressJson
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }

    /**
     * 根据收货地址ID修改 is_selected_address
     *
     * @param addressId         收货地址ID
     * @param isSelectedAddress 是否选中收货地址（0-未选中，1-选中）
     * @return {Promise<boolean>} true修改成功 false修改失败
     */
    updateIsSelectedAddress(addressId,isSelectedAddress){
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/selected/order/settlement",
                method: "POST",
                data: {
                    addressId: addressId,
                    isSelectedAddress:isSelectedAddress
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
}